package top.soulblack.purchasesale.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import top.soulblack.purchasesale.common.Result;
import top.soulblack.purchasesale.model.Customer;
import top.soulblack.purchasesale.service.CustomerService;

import javax.servlet.http.HttpServletRequest;
import java.util.List;


/**
 * create by 小川
 */

@RequestMapping("/sale")
@Controller
public class SaleController {

    @Autowired
    private CustomerService customerService;

    @RequestMapping("/custom_management")
    public String saleManagement(Model model, HttpServletRequest request){
        List<Customer> customers = customerService.selectAll();
        if (request.getParameter("name") != "" && request.getParameter("name") != null){
            String customerName = request.getParameter("name");
            List<Customer> customer = customerService.selectForName(customerName);
            model.addAttribute("customer",customer);
        }
        model.addAttribute("customers",customers);
        return "sale/custom_management";
    }

    @RequestMapping("/list")
    public String saleManagement(){
        return "sale/list";
    }
}
